package com.zephyr.io.chatroom;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class WriteHandler extends Thread {

    private final Socket client;

    public WriteHandler(Socket client) {
        this.client = client;
    }

    @Override
    public void run() {
        try {
            OutputStream out = client.getOutputStream();
            PrintStream printStream = new PrintStream(out);
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入昵称:");
            String line = scanner.nextLine();
            printStream.println(ClientHandler.REGISTER + line);
            printStream.flush();

            do {
                line = scanner.nextLine();
                printStream.println(line);
                printStream.flush();
            } while (!line.equals("bye"));
            this.client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
